﻿/* EntitiesToDTOs. Copyright (c) 2011. Fabian Fernandez.
 * http://entitiestodtos.codeplex.com
 * Licensed by Common Development and Distribution License (CDDL).
 * http://entitiestodtos.codeplex.com/license
 * Fabian Fernandez. 
 * http://www.linkedin.com/in/fabianfernandezb/en
 * */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EntitiesToDTOs.Properties;
using EntitiesToDTOs.Helpers;
using EntitiesToDTOs.Domain;

namespace EntitiesToDTOs.UI
{
    // TODO: ffernandez, investigate to see if is viable to use Error List window of Visual Studio instead of a custom one.
    // http://www.mztools.com/articles/2008/MZ2008022.aspx
    // http://www.mztools.com/articles/2006/MZ2006015.aspx

    /// <summary>
    /// Warnings Window, displays the Warnings produced by the generation of DTOs.
    /// </summary>
    public partial class WarningsWindow : Form
    {
        /// <summary>
        /// Creates a new instance of WarningsWindow.
        /// </summary>
        public WarningsWindow()
        {
            InitializeComponent();

            // Set Window Caption
            this.Text = string.Format(Resources.WarningsWindow_Caption, AssemblyHelper.Version);

            this.lstWarnings.DoubleClick += new EventHandler(lstWarnings_DoubleClick);

            this.lstWarnings.DataSource = WarningsPool.GetWarnings();
            this.lstWarnings.DisplayMember = Resources.Warning_ShortMessage;
        }

        /// <summary>
        /// Executed when the User double-clicks a Warning of the list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void lstWarnings_DoubleClick(object sender, EventArgs e)
        {
            if (this.lstWarnings.SelectedItem != null)
            {
                var warningItem = (this.lstWarnings.SelectedItem as Warning);

                MessageBox.Show(warningItem.Message, Resources.Warning_Caption, 
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        /// <summary>
        /// Executed when the User clicks the Close button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
